package com.aizuda.boot.modules.business.template.entity.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.List;

@Data
@Schema(description = "合同模版添加/修改请求")
public class ContractTemplateAddReqDTO {

    @Schema(description = "模版ID，如果传入则为修改，不传入则为新增")
    private Integer templateId;

    @NotBlank(message = "模版名称不能为空")
    @Schema(description = "模版名称", required = true)
    private String templateName;

    @Schema(description = "适用范围类型：department、personnel")
    private String scopeType;

    @Schema(description = "适用范围值（JSON：部门ID或人员ID列表）")
    private String scopeValue;

    @Schema(description = "创建时是否可编辑：true 可修改，false 不可修改")
    private Boolean editableWhenCreating;

    @Schema(description = "使用说明")
    private String usageInstructions;

    @Schema(description = "合同模版文件ID")
    private Integer templateFileId;

    @Schema(description = "操作类型：draft-保存草稿，published-发布（默认为草稿）", required = false)
    private String status = "draft";

    @Schema(description = "一级合同类型")
    private Integer contractTypeLevel1;

    @Schema(description = "二级合同类型")
    private Integer contractTypeLevel2;

    @Schema(description = "三级合同类型")
    private Integer contractTypeLevel3;

    @NotNull(message = "发布者ID不能为空")
    @Schema(description = "发布者ID", required = true)
    private Long publisherId;

    @Valid
    @Schema(description = "自定义字段列表")
    private List<CustomFieldReqDTO> customFields;

    @Valid
    @Schema(description = "默认字段列表")
    private List<DefaultFieldReqDTO> defaultFields;

    @Data
    @Schema(description = "自定义字段请求")
    public static class CustomFieldReqDTO {

        @NotBlank(message = "字段名称不能为空")
        @Schema(description = "字段名称", required = true)
        private String fieldName;

        @NotBlank(message = "字段类型不能为空")
        @Schema(description = "字段类型（文本、数字、日期、下拉框、金额等）", required = true)
        private String fieldType;

        @Schema(description = "是否必填")
        private Boolean isRequired;

        @Schema(description = "是否支持对方填写")
        private Boolean allowCounterpartyFill;

        @Schema(description = "字段说明")
        private String fieldDescription;

        @Schema(description = "默认值")
        private String defaultValue;

        @Schema(description = "字段显示条件（JSON）")
        private String displayConditions;

        @Schema(description = "排序顺序")
        private Integer sortOrder;
    }

    @Data
    @Schema(description = "默认字段请求")
    public static class DefaultFieldReqDTO {

        @NotNull(message = "默认字段ID不能为空")
        @Schema(description = "默认字段ID（关联contract_field表）", required = true)
        private Long fieldId;

        @Schema(description = "排序字段，值越小越靠前")
        private Integer sortOrder;

        @Schema(description = "是否支持默认值")
        private Boolean supportDefaultValue;

        @Schema(description = "默认值")
        private String defaultValue;

        @Schema(description = "是否支持对方填写")
        private Boolean supportCounterpartyInput;
    }
} 